/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "ODegree.h"
#include "OMethods.h"

O_START_NAMESPACE

void Degree::correct()
{
	double deg	= Methods::abs(m_deg);
	while (deg > 360)
	{
		deg	-= 360;
	}
	if (m_deg < 0)
	{
		deg	= double(360) - deg;
	}

	m_deg	= deg;
}

Degree::Degree()
{
	m_deg		= 0;
}

Degree::Degree(double deg)
{
	m_deg	= deg;
	correct();
}

double Degree::rad()
{
	return m_deg * PI / 180;
}

double Degree::deg()
{
	return m_deg;
}

Degree Degree::fromRadian(double rad)
{
	return Degree(rad * (180 / PI));
}

Degree Degree::operator +(Degree deg)
{
	return Degree(this->deg() + deg.deg());
}

Degree Degree::operator -(Degree deg)
{
	return Degree(this->deg() - deg.deg());
}

Degree Degree::operator *(Degree deg)
{
	return Degree(this->deg() * deg.deg());
}

Degree Degree::operator /(Degree deg)
{
	return Degree(this->deg() / deg.deg());
}

Degree Degree::operator +(double deg)
{
	return Degree(this->deg() + deg);
}

Degree Degree::operator -(double deg)
{
	return Degree(this->deg() - deg);
}

Degree Degree::operator *(double deg)
{
	return Degree(this->deg() * deg);
}

Degree Degree::operator /(double deg)
{
	return Degree(this->deg() / deg);
}


void Degree::operator +=(Degree deg)
{
	m_deg	+= deg.deg();
	correct();
}

void Degree::operator -=(Degree deg)
{
	m_deg	-= deg.deg();
	correct();
}

void Degree::operator *=(Degree deg)
{
	m_deg	-= deg.deg();
	correct();
}

void Degree::operator /=(Degree deg)
{
	m_deg	-= deg.deg();
	correct();
}

void Degree::operator =(Degree deg)
{
	m_deg	= deg.deg();
	correct();
}


void Degree::operator +=(double deg)
{
	m_deg	+= deg;
	correct();
}

void Degree::operator -=(double deg)
{
	m_deg	-= deg;
	correct();
}

void Degree::operator *=(double deg)
{
	m_deg	-= deg;
	correct();
}

void Degree::operator /=(double deg)
{
	m_deg	-= deg;
	correct();
}

void Degree::operator =(double deg)
{
	m_deg	= deg;
	correct();
}


bool Degree::operator !=(Degree deg)
{
	return this->deg() != deg.deg();
}

bool Degree::operator ==(Degree deg)
{
	return this->deg() == deg.deg();
}

bool Degree::operator <(Degree deg)
{
	return this->deg() < deg.deg();
}

bool Degree::operator <=(Degree deg)
{
	return this->deg() <= deg.deg();
}

bool Degree::operator >(Degree deg)
{
	return this->deg() > deg.deg();
}

bool Degree::operator >=(Degree deg)
{
	return this->deg() >= deg.deg();
}


bool Degree::operator !=(double deg)
{
	return this->deg() != deg;
}

bool Degree::operator ==(double deg)
{
	return this->deg() == deg;
}

bool Degree::operator <(double deg)
{
	return this->deg() < deg;
}

bool Degree::operator <=(double deg)
{
	return this->deg() <= deg;
}

bool Degree::operator >(double deg)
{
	return this->deg() > deg;
}

bool Degree::operator >=(double deg)
{
	return this->deg() >= deg;
}


double Degree::sin()
{
	return Methods::sin(*this);
}

double Degree::cos()
{
	return Methods::cos(*this);
}

double Degree::tan()
{
	return Methods::tan(*this);
}

O_END_NAMESPACE
